﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MessageServer.serialize
{
    /**
     * The constructor implementation that should be used to construct
     * objects.
     * */
    public interface ObjectConstructor
    {
        //Function that will be called to create an object of type t
        object construct(Type t);
    }

    //Adapter to be implemented by any serializers that needs to be used
    //in the serialization for BNG
    public interface SerializeFormat
    {
        /**
         * Implement this function to serialize an object into a byte stream.
         * */
        byte[] serialize(object obj);

        /**
         * Implement this function to deserialize the byte array passed to this function into the
         * type indicated by t. This function should use the constructor object to construct objects
         * either type t or any sub objects within the type t. At the end of deserialization, this function
         * should record the length used for deserialization in to len.
         * */
        object deserialize(byte[] bytes, Type t, ObjectConstructor constructor, ref int len);

        /**
         * The lengtht of the bytes that will be created by the object passed to this
         * function.
         * */
        int Length(object obj);

        /**
         * This function implements the functionally dependant reduction in size of the
         * bytes passed to this function.
         * */
        byte[] shorten(byte[] bytes, int len);
    }
}
